package zhtt.redis02.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import zhtt.redis02.entity.DemoInfo;
import zhtt.redis02.service.DemoInfoService;


/**
 * 测试类.
 * @author Angel(QQ:412887952)
 * @version v.0.1
 */
@Controller
public class DemoInfoController {
	
	@Autowired
	private DemoInfoService demoInfoService;
	 
	@RequestMapping
	public @ResponseBody String save(String name,String pwd){
		try{
			DemoInfo d=new DemoInfo();
			d.setName(name);
			d.setPwd(pwd);
			demoInfoService.save(d);
			return "success";
		}catch (Exception e){
			return  e.getMessage();
		}
	}

	@RequestMapping("/get")
	public @ResponseBody String get(int id){
	    DemoInfo loaded = demoInfoService.findById(id);
	    System.out.println("---【loaded】="+loaded);
	    DemoInfo cached = demoInfoService.findById(id);
	    System.out.println("---【cached】="+cached);
	    loaded = demoInfoService.findById(2);
	    System.out.println("loaded2="+loaded);
	    return cached==null?"null":cached.toString();
	} 
	
	
	@RequestMapping("/delete")
	public @ResponseBody String delete(long id){
	    demoInfoService.deleteFromCache(id);
	    return "ok";
	} 
	
	@RequestMapping("/test1")
	public @ResponseBody String test1(){
	    demoInfoService.test();
	    System.out.println("DemoInfoController.test1()");
	    return "ok";
	} 
	
}
